package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapePlant;
import com.ruoyi.grape.service.IGrapePlantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 种植信息Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/plant")
public class GrapePlantController extends BaseController
{
    @Autowired
    private IGrapePlantService grapePlantService;

    /**
     * 查询种植信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:plant:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapePlant grapePlant)
    {
        startPage();
        List<GrapePlant> list = grapePlantService.selectGrapePlantList(grapePlant);
        return getDataTable(list);
    }

    /**
     * 导出种植信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:plant:export')")
    @Log(title = "种植信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapePlant grapePlant)
    {
        List<GrapePlant> list = grapePlantService.selectGrapePlantList(grapePlant);
        ExcelUtil<GrapePlant> util = new ExcelUtil<GrapePlant>(GrapePlant.class);
        util.exportExcel(response, list, "种植信息数据");
    }

    /**
     * 获取种植信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plant:query')")
    @GetMapping(value = "/{plantId}")
    public AjaxResult getInfo(@PathVariable("plantId") Long plantId)
    {
        return success(grapePlantService.selectGrapePlantByPlantId(plantId));
    }

    /**
     * 新增种植信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plant:add')")
    @Log(title = "种植信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapePlant grapePlant)
    {
        return toAjax(grapePlantService.insertGrapePlant(grapePlant));
    }

    /**
     * 修改种植信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plant:edit')")
    @Log(title = "种植信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapePlant grapePlant)
    {
        return toAjax(grapePlantService.updateGrapePlant(grapePlant));
    }

    /**
     * 删除种植信息
     */
    @PreAuthorize("@ss.hasPermi('grape:plant:remove')")
    @Log(title = "种植信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{plantIds}")
    public AjaxResult remove(@PathVariable Long[] plantIds)
    {
        return toAjax(grapePlantService.deleteGrapePlantByPlantIds(plantIds));
    }
}
